<?php
function truncate($string, $length = 80, $etc = '...', $charset='UTF-8',
                                  $break_words = false, $middle = false){
	
                                  	
	$string = strip_tags($string);
	
    if ($length == 0)
        return '';
 
    if (strlen($string) > $length) {
        $length -= min($length, strlen($etc));
        if (!$break_words && !$middle) {
            $string = preg_replace('/\s+?(\S+)?$/', '', mb_substr($string, 0, $length+1, $charset));
        }
        if(!$middle) {
            return mb_substr($string, 0, $length, $charset) . $etc;
        } else {
            return mb_substr($string, 0, $length/2, $charset) . $etc . mb_substr($string, -$length/2, $charset);
        }
    } else {
        return $string;
    }
}


function replace_translations($text){
	
	preg_match_all("/%(.*?)%/x",
                $text, $out);

	if(!isset($out[0]) || !$out[0]) return $text;


	foreach($out[0] as $param){
		$text = str_replace($param, __($param), $text);
	}

	return $text;
}


function include_partial_and_replace_translations($partial, $params = array()){
	$content = get_partial($partial, $params);

	echo replace_translations($content);
}